<template>

    <el-descriptions>
        <el-descriptions-item v-for="(item, index) in tableItem" :key="index" :label="item.label">
            <span v-if="item.filterable">{{ item.filter(form)|filterNull }}</span>
            <span v-else :class="'contractReportNumber'==item.prop||'procurementReportNumber'==item.prop?'table-blue-text':''" @click="goDetail(item)">{{ form[item.prop]|filterNull }}</span>
        </el-descriptions-item>
    </el-descriptions>

</template>
<script>
import { OrderParam } from '@/api/finance/manage/collect/api.js';
import { orderCarParam } from "@/api/gps/gpsList";
export default {
    dicts: ['quota_rent_type', 'car_business_type'],
    props: {
        form: {
            type: Object,
            defaut: () => ({})
        }
    },
    data() {
        return {
            tableItem: [],
        }
    },
    created() {
        this.initTable()
    },
    methods: {
        initTable() {
            this.tableItem = [
                {
                    label: "车架号",
                    prop: "vinNo",
                    minWidth: '130',
                    type: "text",
                },
                {
                    label: "车牌号",
                    prop: "carNo",
                    type: "text",
                },
                {
                    label: "品牌/车型/车款",
                    prop: "brandName",
                    type: "text",
                    minWidth: '150',
                    filterable: true,
                    filter: val => {
                        return (val.brandName?val.brandName:'--') + '/' + (val.seriesName?val.seriesName:'--') + '/' + (val.modelName?val.modelName:'--')
                    }
                },
                {
                    label: "车辆产权",
                    prop: "propertyRightName",
                    type: "text",
                },
                {
                    label: "车辆归属",
                    prop: "ascription",
                    type: "text",
                },
                {
                    label: "车辆运营",
                    prop: "operationsName",
                    type: "text",
                },
                {
                    label: "车辆大区",
                    prop: "region",
                    type: "text",
                },
                {
                    label: "合同禀议编号",
                    prop: "contractReportNumber",
                    type: "text",
                },
                {
                    label: "合同开始日期",
                    prop: "contractStartTime",
                    type: "text",
                },
                {
                    label: "合同结束日期",
                    prop: "contractEndTime",
                    type: "text",
                },
                {
                    label: "客户名称",
                    prop: "customerName",
                    type: "text",
                },
                {
                    label: "采购禀议编号",
                    prop: "procurementReportNumber",
                    type: "text",
                },
                {
                    label: "产品类型",
                    prop: "contractType",
                    type: "text",
                    filterable: true,
                    filter: (val) => {
                        let result = [];
                        this.dict.type.quota_rent_type?.map((item) => {
                            if ((item.value * 1) == val.contractType) {
                                result.push(item.label);
                            }
                        });
                        return result && result?.join("/");
                    },
                },
                {
                    label: "车辆状态",
                    prop: "businessType",
                    type: "text",
                    filterable: true,
                    filter: (val) => {
                        let result = [];
                        this.dict.type.car_business_type?.map((item) => {
                            if ((item.value * 1) == val.businessType) {
                                result.push(item.label);
                            }
                        });
                        return result && result?.join("/");
                    },
                },
                {
                    label: "批次号",
                    prop: "flowBusinessId",
                    type: "text",
                },

            ];
        },

        goDetail(item){
            if('contractReportNumber'==item.prop){
                if(!this.form.mainOrderNo){
                    return
                }
                orderCarParam(this.form.mainOrderNo)
                    .then(res => {
                        if (res.code == 200) {

                            this._toPage({
                                name: "SuborderDetail",
                                query: {
                                    id: res.data.orderCarId,
                                    orderId: res.data.orderCarCode
                                },
                            });

                            // this.$router.push({
                            //     name: 'OrderDetails',
                            //     query: {
                            //         type: res.data.carType,
                            //         beFrom: 'OrderView',
                            //         orderId: res.data.orderId,
                            //         preOrderId: res.data.preOrderId,
                            //         calcSchemeId: res.data.calcSchemeId,
                            //         isMenu: this.$route.query.isMenu,
                            //     },
                            // })
                        } else {
                            throw new Error(res);
                        }
                    })
            }else

                if('procurementReportNumber'==item.prop){
                if (2 == this.form.purchaseSource) {
                    //订单
                    this._toPage({
                        name: "OrderPurchase",
                        query: {
                            purchaseOrderId: this.form.purchaseOrderId,
                            type: "detail",
                            pageType: "订单采购详情",
                        },
                    });
                } else if(1 == this.form.purchaseSource){
                    this._toPage({
                        name: "PurchaseAdd",
                        query: {
                            purchaseOrderId: this.form.purchaseOrderId,
                            type: "detail",
                            pageType: "采购详情",
                        },
                    });
                }
            }
        }
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-descriptions{
    margin: 5px -15px 0 !important;
}

::v-deep .el-descriptions-item__cell {
    padding: 7px 15px !important;
}
</style>
